<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>人事管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/xadmin.css">
     <script src="../../static/js/jquery-1.12.4.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/xadmin.js"></script>
</head>

<body>
    <div class="x-body layui-anim layui-anim-up">
        <form class="layui-form">

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>部门名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" lay-verify="required" 
                        autocomplete="off" class="layui-input">
                </div>
               
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>详细描述
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="remark" name="remark" required="" lay-verify="required"
                        autocomplete="off" class="layui-input">
                </div>
				
            </div>
	 		
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button  id='submit' class="layui-btn" lay-filter="add" lay-submit="submit">
                    &nbsp;&nbsp;添加&nbsp;&nbsp;
                </button>
            </div>
        </form>
    </div>
    <script>
        layui.use(['form', 'layer'], function () {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer;

            //监听提交
            form.on('submit(add)', function (data) {
                //发异步，把数据提交,ajax 代码
                $.ajax({
                    url: '../../addDept.action',
                    type: 'post',
                    data: data.field,
                    success: function (data) {
                        if (data == 1) {
                            layer.alert(
                                "增加成功", { icon: 6 },
                                function () {
                                    // 获得frame索引
                                    var index = parent.layer.getFrameIndex(window.name);
                                    //关闭当前frame
                                    parent.layer.close(index);
                                    //修改成功后刷新父界面
                                    window.parent.location.reload();
                            });
                        }
                        else {
                        	 layer.alert("增加信息失败！", { icon: 2 })
                        }
                    },
                    error: function (e) {
                        layer.alert("error！提交失败！")
                    }
                });
                return false;
            });


        });
        
        $("#name").keyup(function(){
        	var name=$(this).val();
            $.ajax({
                url:"../../checkDeptName.action",
                type:"get",
                data:{"name":name},
                success:function(data){
                 if(data==1){
                  //开启提交按钮
                	$("#submit").removeClass("layui-btn-disabled").attr("disabled",false);
                 }else {
                layer.msg('部门名已存在',{icon:7});
                  //把提交按钮关闭
                  $("#submit").addClass("layui-btn-disabled").attr("disabled",true)
                  
                 }

                },
                error:function(){
                 alert("执行异常!");
                }
               })
        })
    </script>

</body>

</html>